<?php
   namespace app\admin\controller;
   class Homeinfo extends Base{
	   public $mec;
	   function __construct(){
  		parent::__construct();
      $this->mec=new \app\admin\controller\Memcache();
  	}
	  //首页轮播图
      function lbt_data($page=1){
          $new=new \app\index\controller\Fy($page);
      	  $spcont=$new->data('sp',5);//data(表名,每页显示的页数);
	      $sp=\think\Db::name('sp')->field('id,sp_name,sp_shop_num,brand_id,fl_id')->limit($spcont['limit'],$spcont['num'])->select();
		  $fy=$new->list_page($new,'/homeinfo/lbt_data',$spcont['count'],['上一页','下一页'],'class,class_','page_a,a_page');//list_page(对象,url,总页数,['上一页的文字','下一页的文字'],上下页激活按钮class名/禁止点击class名,页码选中class名/没选中class名);
		  foreach($this->mec->mem->get('fl') as $v){
			 $after=explode('-',$v['fl_name']);
		     $fl[$v['id']]=$after[count($after)-1];
		  }
		  foreach($sp as $v){
		    $spid[]=$v['id'];
		  }
		  $img_list=\think\Db::name('img_list')->where('sp_id in ('.join(',',$spid).')')->select();//商品缩略图
          foreach($img_list as $v){
			 $frist=explode(',',$v['img_list']);
		     $img[$v['sp_id']]=$frist[0];
		  }
		  $this->assign(['sp'=>$sp,'fl'=>$fl,'img'=>$img,'brand'=>$this->mec->mem->get('brand'),'fy'=>$fy]);
	      return $this->fetch('index/home_lbt');
	  }


	  function lbt_list(){
	     $img=\think\Db::name('info')->where('key','lunbotu')->find();
		 if($img){
				$img_=explode(',',$img['value']);
				$spid=explode(',',$img['cid']);
				die(JSON_encode(['status'=>'ok','lbt'=>$img_,'spid'=>$spid]));
		 }else{
			   die(JSON_encode(['status'=>'fail']));
		 }
	  }


	  function lbt_save(){
	       $p=input('post.');
		   if($p['lbt']=='del' or $p['spid']=='del'){
		        $lunbotu=\think\Db::name('info')->where('key','lunbotu')->delete();
		   }else{
		        $res=\think\Db::name('info')->where('key','lunbotu')->find();
		        if($res){
		                $lunbotu=\think\Db::name('info')->where('key','lunbotu')->update(['value'=>join(',',$p['lbt']),'cid'=>join(',',$p['spid'])]);
		        }else{
				        $lunbotu=\think\Db::name('info')->insert(['key'=>'lunbotu','value'=>join(',',$p['lbt']),'cid'=>join(',',$p['spid'])]);
		        }
	     }
		   if($lunbotu){
		      die(JSON_encode(['status'=>'ok']));
		   }else{
		      die(JSON_encode(['status'=>'fail']));
		   }
	  }

   }
 ?>